//Colors that can be animated
var arColors = ["backgroundColor", "color", "borderColor", "borderTopColor", "borderBottomColor", "borderLeftColor", "borderRightColor"];
var timer;
function ConvertToPixels(_str, prop) {
		if (/px$/.test(_str)) { return parseInt(_str); }
		_context = document.body;

		var tmp = document.createElement('div');
		tmp.style.position = 'absolute';
		tmp.style.backgroundColor = 'red';
		tmp.style.width = '100px';

		if (/%$/.test(_str)){
			if(prop == "left" || prop == "width") {
	 			tmp.style.width = _str;
			} else if(prop == "top" || prop == "height"){
				tmp.style.height = _str;	
			}
		} else {
			tmp.style.borderStyle = 'solid';
			tmp.style.borderBottomWidth = '0';					
			tmp.style.borderTopWidth = _str;
		}

		_context.appendChild(tmp);
		if(prop == "left" || prop == "width") {
			var px = tmp.offsetWidth;
		} else{
			var px = tmp.offsetHeight;
		}
		_context.removeChild(tmp);

		return px || 0;
	};

function normalize(_elem, _style) {
  var nonPixels = /(em|ex|pt|%)$/;

  var computedStyle;
  if (typeof _elem.currentStyle != 'undefined')
  {
    computedStyle = _elem.currentStyle;
    var val = computedStyle[_style];
    if (nonPixels.test(val))
      { return convertToPixels(val, _elem); }
  }
  else
    { computedStyle = document.defaultView.getComputedStyle(_elem, null); }

  return computedStyle[_style];
}

var jFx = {
	__dragging: "", //actual dragging object, patch for multiple objects
	flash: function(opts){
			if(!opts) opts={};
			aTime = opts.times || 5;
			aSpeed = opts.speed || 100;
			aColor = opts.color || '#FF0000';
			var tmp = this.chain();
			var org = this.$$("backgroundColor");
			for(i=0;i<aTime;i++){
				tmp = tmp.animate({backgroundColor: aColor, duration: aSpeed}).animate({backgroundColor: org, duration: aSpeed});
			}
			tmp.end();
			return this;
		   },

	wiggle: function(opts){
				if(!opts) opts = {};
				var bPeriod = opts.period || 500;
				var bRepeat = opts.repeat || 0;
				var bValue = opts.value || 15;
				var vOrigLeft = this.gL();
				var vOrigTop = this.gT();
				var bCounter = 1;
				var target = this;
				
				function randomPos(limit){
					rndX = (Math.random() * limit) * (Math.round(Math.random()) == 0 ? -1 : 1);
					rndY = (Math.random() * limit) * (Math.round(Math.random()) == 0 ? -1 : 1);
					xVal = Math.round(Math.random()) == 0 ? vOrigLeft : rndX;
					yVal = Math.round(Math.random()) == 0 ? vOrigTop : rndY;
					return {
							left: xVal,
							top: yVal
							}
				}
				this.$$({
						position: "absolute",
						left: vOrigLeft + "px",
						top: vOrigTop + "px"
						});
				var timer = setInterval(function(){
											v = randomPos(bValue);
											target.$$({
														left: vOrigLeft + v.left + "px",
														top:  vOrigTop  + v.top  + "px"
													});

											if(bRepeat > 0) {
												if(bCounter >= bRepeat){
													clearInterval(timer);
												} else {
													bCounter++;
												}
											}
										}, bPeriod);
				
				return this;
				
			},

	lightbox: function(opts){
				if (parseInt(navigator.appVersion)>3) {
					if (navigator.appName=="Netscape") {
						var winW = window.innerWidth;
						var winH = window.innerHeight;
					}
					if (navigator.appName.indexOf("Microsoft")!=-1) {
						var winW = document.body.offsetWidth;
						var winH = document.body.offsetHeight;
					}
				}
				
				function hideAll(){
						divBg.fadeOut();
						divMsg.fadeOut();
						if(divTitle) divTitle.fadeOut();
						if(divClose) divClose.fadeOut();
				}
				
				function loadImage( url ) {
/*						if( container.is( '.loading' ) ) { return; }
						container.addClass( 'loading' );*/
						var img = new Image();
						img.src = url;
						img.onload = function() {
												img.style.display = 'none';
					
												var maxWidth = ( winW - parseInt( divMsg.$$( 'padding-left' ),10 ) - parseInt( divMsg.$$( 'padding-right' ), 10 ) ) - 100;
												var maxHeight = ( winH - parseInt( divMsg.$$( 'padding-top' ),10 ) - parseInt( divMsg.$$( 'padding-bottom' ), 10 ) ) - 100;
						
												if( img.width > maxWidth || img.height > maxHeight ) { // One of these is larger than the window
													var ratio = img.width / img.height;
													if( img.height >= maxHeight ) {
														img.height = maxHeight;
														img.width = maxHeight * ratio;
													} else {
														img.width = maxWidth;
														img.height = maxWidth * ratio;
													}
												}
						
												divMsg.chain()
													.animate({
															height: img.height,
															top: Math.round( (winH - img.height - parseInt( divMsg.$$( 'padding-top' ),10 ) - parseInt( divMsg.$$( 'padding-bottom' ),10 ) ) / 2 ) + 'px',
															easing: "sineInOut"
															})
													  .animate({
																width: img.width,
																left: Math.round( (winW - img.width - parseInt( divMsg.$$( 'padding-left' ),10 ) - parseInt( divMsg.$$( 'padding-right' ),10 ) ) / 2 ) + 'px',
																easing: "sineInOut",
																post: function(){
																	divMsg.insert(img);
																	j$(img).fadeIn({
																					post: function(){
																										if(divTitle){
																											if(divTitle.getOpacity() < 1) divTitle.fadeIn();
																											divTitle.$$({
																														top: parseCss(divMsg.$$("top")).value + divMsg.gH() + (parseCss(divMsg.$$("padding")).value * 2) + "px",
																														left: divMsg.$$("left"),
																														width: divMsg.gW() + "px"
																														});
																											divTitle.slideDown({easing: "sineOut"}); 
																										}

																										if(divClose) {
																											if(divClose.getOpacity() < 1) divClose.fadeIn();

																											divClose.$$({
																														top: parseCss(divMsg.$$("top")).value + "px",
																														left: divMsg.$$("left"),
																														width: divMsg.gW() + "px",
																														display: "block",
																														opacity: "1.0"
																														});
																											divClose.animate({
																															top: parseCss(divClose.$$("top")).value - 24 + "px",
																															easing: "sineOut"
																															});
																											
																										}
																									}
																					});
																	
																}
															})
													.end();
										}
				}

				if(!opts) opts = {};
				var oLink = this.href;
				var oTitle = this.title || null;
				var oClose = typeof(opts.closeButton) == "undefined" ? true : opts.closeButton;
				var target = this;
				width = opts.width || 640;
				height = opts.height || 480;

				var divBg = jarvis.toDOM('<div class="blackOverlay"></div>');
				if(oTitle != null) var divTitle = jarvis.toDOM('<div>'+oTitle+'</div>');
				if(oClose != null) var divClose = jarvis.toDOM('<div><a>CERRAR</a></div>');
				var divMsg = jarvis.toDOM('<div></div>');

				divBg.$$({
							display: "none",
							position: "absolute",
							top: "0%",
							left: "0%",
							width: "100%",
							height: "100%",
							backgroundColor: "black",
							zIndex: 1001,
							opacity: "0.8"
					   });
				
				divMsg.$$({
							display: "none",
							position: "absolute",
							top:  Math.round( (winH - 48 ) / 2 ) + 'px',
							left: Math.round( (winW - 48 ) / 2 ) + 'px',
							padding: "16px",
							backgroundColor: "white",
							zIndex: 1002,
							overflow: "auto"
						});
				
				if(divTitle){
					divTitle.$$({
								display: "none",
								position: "absolute",
								backgroundColor: "white",
								zIndex: 1002,
								paddingLeft: divMsg.$$("padding"),
								paddingRight: divMsg.$$("padding"),
								paddingTop: parseCss(divMsg.$$("padding")).value / 2,
								paddingBottom: parseCss(divMsg.$$("padding")).value / 2
								});
				}
				
				if(divClose){
					divClose.$$({
								display: "none",
								height: "24px",
								position: "absolute",
								backgroundColor: "white",
								paddingLeft: parseCss(divMsg.$$("padding")).value + 6 + "px",
								paddingRight: "10px",
								paddingTop: parseCss(divMsg.$$("padding")).value / 2,
								paddingBottom: parseCss(divMsg.$$("padding")).value / 2,
								textAlign: "right"
								});
				}

				if(oClose == null){
					divBg.click(function(){
									hideAll();
								});
				} else {
					divClose.find("a").click(function(){
										hideAll();
									});
				}

				divBg.insert(divMsg);
				if(divTitle) divBg.insert(divTitle);
				if(divClose) divBg.insert(divClose);

				j$(document.body).insert(divBg);

				target.each(function(a){
					j$(a).click(function(event){
									event = event || window.event;
									divBg.fadeIn();
									divMsg.empty();
									divMsg.fadeIn({post: function(){
															if(oLink.substr(-4) == ".png" || oLink.substr(-4) == ".jpg" || oLink.substr(-4) == ".gif" ){
																loadImage(oLink);
															} else
															if(oLink.indexOf('http://') === 0){
																inside = '<iframe src="'+oLink+'"></iframe>';
															}
														}
												});
	
									a.cancelEvents(event);
									return false;
								});
				});
		   },

	scrollTo: function(opts, _after){
					if(!opts) opts = {};
					oX = opts.x || null;
					oY = opts.y || null;
					var time = opts.duration || 400;
					var steps = time / 24;
					var curValues = {};
					var easingVal = opts.easing || "linear";
					var timeCount = 0;
					var target = this;
					var postFn = opts.post || null;
					var preFn = opts.pre || null;
					
					if(preFn !== null) preFn.call(target);
					
					if(oX != null) curValues["x"] = target.scrollLeft;
					if(oY != null) curValues["y"] = target.scrollTop;
		
					clearInterval(target.timer);
					target.timer = setInterval(function(){
													opts.each(function(value, el){
														var tipo = el == "y" ? "Top" : "Left";
														el = el.toLowerCase();
														if(el != "each" && el != "duration" && el != "easing" && el != "post" && el != "pre" && el != "flatten"){
															d = (timeCount / time) > 1 ? 1 : (timeCount / time);
															if(typeof(curValues[el]) == "undefined"){
																curValues[el] = target["scroll"+tipo];
															}
															val = Math.floor(curValues[el]);
	
	//														val = curValues[el] === "undefined" ? val = 0 : val;
															val += ( (value - curValues[el]) * jEasing[easingVal](d) );
	
															target["scroll"+tipo] = val;
														}
													});
	
													if(timeCount > time){
														postFn && setTimeout(postFn, 1);
														_after && setTimeout(_after, 1);
														clearInterval(target.timer);
													}
													timeCount+=steps;
												}, steps);
					
				  },

	animate: function(opts, _after){
				target=this;
				keys=Object.keys(opts);
				filter=/^(each|duration|flatten|easing|post|pre|sortnum)$/i;
				splitUnit=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i;
				isColor=/^(background|border(|left|right|top|bottom))color$/i;
				duration=opts.duration || 400;
				easing=opts.easing || 'linear';
				orig={};
				i=1;
				kCount=new Array();

				for(j=0; j<keys.length;j++ ){
					if(!filter.test(keys[j])){
						kCount.push(keys[j]);
					}
				}

				optsLength = kCount.length;

				delete keys;
				delete kCount;

				if(opts.pre) opts.pre();
				orig.post = false;
				
				for(el in opts){
					if(!filter.test(el)){
						if(!isColor.test(el)){
							if(el == 'opacity'){
								orig.ini = parseFloat(this.gO());
								orig.end = parseFloat(opts[el]);
								orig.u = '';
							} else {
								curr = splitUnit.exec(opts[el]);
								orig.ini = parseFloat(splitUnit.exec(this.computed$$(el))[2]);
								orig.end = parseFloat(curr[2]);
								orig.iniu = splitUnit.exec(this.numCss(el))[3];
								orig.endu = curr[3] || 'px';
								console.log(orig.ini+orig.iniu + ' -> ' +orig.end+orig.endu);
								if ( orig.endu !== 'px') {
									target.style[el] = orig.end + orig.endu;
									actt = parseFloat(target.computed$$(el));
									orig.ini = (orig.end / actt) * orig.ini;
									if(orig.ini == 'NaN') orig.ini = 0;
									target.style[el] = orig.ini + orig.endu;
								}
							}
						} else {
							orig.ini = target.$$(el);
							orig.end = opts[el];
							orig.endu = '';
						}
						if(i==optsLength) {
							orig.post = function(){
											opts.post && setTimeout(opts.post,1);
											_after && setTimeout(_after,1);
										}
						}
						target.processAnimation(el, duration, orig.ini, orig.end, easing, orig.endu, orig.post);
						++i;
					}
				}

				delete orig;
				delete keys;
				return this;
		},

	processAnimation: function(property, duration, start, end, easing, u, post){
							var counter=0;
							var steps=18; //duration/24;
							var target = this;
							var isHexColor=/^#([a-z0-9]*)/i;
							var isColor=/^(background|border(|left|right|top|bottom))color$/i;
							var orig={};
							if(property=='height' || property=='width'){
								orig.overflow  = target.$$('overflow');
								orig.overflowX = target.$$('overflowY');
								orig.overflowY = target.$$('overflowX');
								target.$$("overflow","hidden");
							}
							var timer = setInterval(function(){
															diff=(counter / duration) > 1 ? 1 : (counter / duration);
															if(!isColor.test(property)){
																val = start + ( (end - start) * jEasing[easing](diff) );
															} else {
																dB = jColors.cssColor2rgb(start);
																dE = jColors.cssColor2rgb(end);
		
																r = parseInt( parseInt(dB[0])+(dE[0]-dB[0])*jEasing[easing](diff) );
																g = parseInt( parseInt(dB[1])+(dE[1]-dB[1])*jEasing[easing](diff) );
																b = parseInt( parseInt(dB[2])+(dE[2]-dB[2])*jEasing[easing](diff) );
		
																val  = 'rgb('+r+','+g+','+b+')';
															}
		
															target.$$(property, val+u);
		
															if(counter > duration){
																clearInterval(timer);
																if(property=='height'||property=='width'){
																	target.$$( 'overflow', orig.overflow);
																	target.$$('overflowX', orig.overflowX);
																	target.$$('overflowY', orig.overflowY);
																}
																post && post();
															}
		
															counter += steps;
													}, steps);
	},

	slideUp: function(opts, _after){
				if(!opts) opts = {};
				var target = this;
				var time =  opts.duration || 400;
				var easingVal = opts.easing || "linear";
				if((parseCss(this.$$("height")).value > 0 || this.offsetHeight > 0) && this.$$("display") != "none") {
					if(this.$$('height') == "auto") this.orig["autoHeight"] = true;
					if(!this.orig["height"]) this.orig["height"] = this.gH();
					if(!this.orig["paddingTop"]) this.orig["paddingTop"] = this.$$("paddingTop");
					if(!this.orig["paddingBottom"]) this.orig["paddingBottom"] = this.$$("paddingBottom");
					if(!this.orig["borderTopWidth"]) this.orig["borderTopWidth"] = this.$$("borderTopWidth");
					if(!this.orig["borderBottomWidth"]) this.orig["borderBottomWidth"] = this.$$("borderBottomWidth");

					this.animate({
								 height: 0,
								 paddingTop: 0,
								 paddingBottom: 0,
								 duration: time,
								 easing: easingVal,
								 post: function(){
									 		target.$$("display","none");
									   }
								}, _after);
				}
				return this;
			 },

	slideDown: function(opts, _after){
				if(parseCss(this.$$("height")).value == 0 || this.$$("display") == "none"){
					if(!opts) opts = {};
					origOverflow = this.$$('overflow');
					var time =  opts.duration || 400;
					var easingVal = opts.easing || "linear";
					var target = this;
					var oPost = opts.post || null;

					if(this.$$('height') == "auto") this.orig["autoHeight"] = true;

					this.$$("display","block");

					if(!this.orig["height"] || this.orig["height"] == 0) this.orig["height"] = this.gH();
					if(!this.orig["paddingTop"]) this.orig["paddingTop"] = this.$$("paddingTop");
					if(!this.orig["paddingBottom"]) this.orig["paddingBottom"] = this.$$("paddingBottom");
					if(!this.orig["borderTopWidth"]) this.orig["borderTopWidth"] = this.$$("borderTopWidth");
					if(!this.orig["borderBottomWidth"]) this.orig["borderBottomWidth"] = this.$$("borderBottomWidth");

					this.$$("height", "0");

					this.animate({
								 height: this.orig["height"]+"px",
								 paddingTop: this.orig["paddingTop"],
								 paddingBottom: this.orig["paddingBottom"],
								 duration: time,
								 easing: easingVal,
								 post: function(){
									 		target.$$('overflow',origOverflow);
											if(target.orig["autoHeight"] == true) target.$$('height','auto');
									 	}
								}, _after);
				}
				return this;
			 },

	move: function(opts, _after){
				if(!opts) opts = {};
				var time =  opts.duration || 400;
				var easingVal = opts.easing || "linear";
				nLeft = opts.left || this.gL();
				nTop = opts.top || this.gT();

				this.animate({
							left: nLeft,
							top: nTop,
							easing: easingVal,
							duration: time
							}, _after);
				return this;
		  },

	fadeOut: function(opts, _after){
				if(!opts) opts = {};
				var target = this;
				if(this.$$("visibility") !== "hidden" && this.$$("display") !== "none"){

					if(!this.orig["opacity"]) this.orig["opacity"] = this.$$("opacity");

					time = opts.duration || 400;
					easingVal = opts.easing || "linear";
					postVal = function(){
									target.$$("visibility","hidden");
									opts.post && opts.post();
							}
					this.animate({
								opacity: 0,
								duration: time,
								easing: easingVal,
								post: postVal
								}, _after);
				}
				return this;
			 },

	fadeIn: function(opts, _after){
				if(!opts) opts = {};
				target = this;
				if(target.$$("visibility") == "hidden" || target.$$("display") == "none"){

					if(!target.orig["opacity"]) target.orig["opacity"] = target.$$("opacity");
					
					time = opts.duration || 400;
					easingVal = opts.easing || "linear";
					postVal = function(){
								if(typeof opts.post == 'function') opts.post.call(target);
							  }
					if(target.$$("display") == "none") target.$$("display","block");
					target.$$("opacity","0");
					target.animate({
								opacity: target.orig["opacity"],
								duration: time,
								easing: easingVal,
								pre: function(){
										target.$$("visibility","visible");
									  },
								post: postVal
								}, _after);
				}
				return target;
			},

	drag: function(opts, _after){
				if(!opts) opts = {};
				var el = this;
				el.axis = opts.axis || "XY";
				el.oX = el.oY = 0;
				el.isDragging = false;
				el.origZ = 0;
				el.post = opts.post || null;
				el.pre = opts.pre || null;
				el.drop = opts.drop || null;
				el.dragging = opts.dragging || null;
				el.snapY = opts.snapY || 0;
				el.snapX = opts.snapX || 0;
				var tmpY =0;
				var tmpX = 0;

				el.onmousedown = function(e){
									jFx.__dragging = el;
									if (window.event) e=window.event;
									var mouseX = e.clientX + document.body.scrollLeft;
									var mouseY = e.clientY + document.body.scrollTop;

									var dragX = jFx.__dragging.gL() || 0;
									var dragY = jFx.__dragging.gT() || 0;

									el.originalX = dragX;
									el.originalY = dragY;
								
									el.oX = mouseX - dragX;
									el.oY = mouseY - dragY;
									
									el.origZ = el.$$("zIndex");
///									el.$$("zIndex", 9999);
									
									el.isDragging = true;

									if(el.pre !== null) el.pre.call(el);

									return false;
								}

				document.onmousemove = function(e) {
											if (jFx.__dragging.isDragging) {									
												if (window.event) e=window.event;
												pageX = e.clientX + document.body.scrollLeft;
												pageY = e.clientY + document.body.scrollTop;

												var newX = pageX - jFx.__dragging.oX;
												var newY = pageY - jFx.__dragging.oY;
												
												if(jFx.__dragging.parentNode.style.position == "relative"){
													newX -= jCss.getOffset.call(jFx.__dragging.parentNode).left;
													newY -= jCss.getOffset.call(jFx.__dragging.parentNode).top;
												}

												if(jFx.__dragging.axis != "Y") {
													if(jFx.__dragging.snapX > 0){
														if(Math.abs(tmpX) >= jFx.__dragging.snapX){
															tmpX = (tmpX > 0 ? jFx.__dragging.snapX : -jFx.__dragging.snapX);
															jFx.__dragging.style.left = jFx.__dragging.gL() + tmpX + "px";
															tmpX = 0;
														} else {
															tmpX = newX - parseInt(jFx.__dragging.$$("left"));
														}
													} else {
														jFx.__dragging.$$("left", newX + "px");
													}
												}

												if(jFx.__dragging.axis != "X") {
														if(jFx.__dragging.snapY > 0){
															if(Math.abs(tmpY) >= jFx.__dragging.snapY){
																tmpY = (tmpY > 0 ? jFx.__dragging.snapY : -jFx.__dragging.snapY);
																jFx.__dragging.style.top = jFx.__dragging.gT() + tmpY + "px";
																tmpY = 0;
															} else {
																tmpY = newY - parseInt(jFx.__dragging.$$("top"));
															}
														} else {
															jFx.__dragging.$$("top", newY + "px");
														}
												}

												if(jFx.__dragging.dragging != null) jFx.__dragging.dragging(newX, newY);
											}
											return false;
									   }

				document.onmouseup = function(e) {
										if (!jFx.__dragging.isDragging) return;
										jFx.__dragging.isDragging = false;
										el.$$("zIndex", el.origZ);
										if(el.post !== null) el.post.call(el);
										tmpY = 0;
										return false;
									 }
				_after && setTimeout(_after,1);
				return this;
			},

	pause: function(duration, _after){
				clearInterval(this.timer);
				if(duration){
					setTimeout(function() {
									_after && setTimeout(_after,1);
								}, duration);
				}
		   },

	resizable: function(opts){/*
					if(!opts) opts = {};
					var aAxis = opts.axis || "XY";
					aAxis = aAxis.toUpperCase();
					var snapY = opts.snapY || 0;
					var snapX = opts.snapX || 0;
					var minX = minY = 0;
					var tmpY =0;
					var tmpX = 0;
					if(opts.min){
						if(typeof(opts.min) === "string" && opts.min.toLowerCase().indexOf('x') > -1){
							bMin = opts.min.split("x");
							minX = parseInt(bMin[0]);
							minY = parseInt(bMin[1]);
						} else {
							minX = aAxis == "X" ? minX = opts.min : 0;
							minY = aAxis == "Y" ? minY = opts.min : 0;
						}
					}
					bMax = opts.max || 0;
					var target = this;
					this.style.overflow = this.$$("overflow") || "hidden";

					if(this.nodeName.match(/canvas|textarea|input|select|button|img/i)){
						var wrapDiv = document.createElement('DIV');
						this.style.position = "relative";
	
//						wrapDiv.style.backgroundColor = "blue";
						wrapDiv.style.position = this.$$("position");

						wrapDiv.style.left = (parseInt(this.$$('left')) || 0) + "px";
						wrapDiv.style.top = (parseInt(this.$$('top')) || 0) + "px";
						
						wrapDiv.style.height = this.offsetHeight + "px";
						wrapDiv.style.width = this.offsetWidth + "px";
	
						wrapDiv.style.marginLeft = this.css("marginLeft");
						wrapDiv.style.marginTop = this.css("marginTop");
						wrapDiv.style.marginRight = this.css("marginRight");
						wrapDiv.style.marginBottom = this.css("marginBottom");
						
						this.style.marginLeft= 0;
						this.style.marginTop= 0;
						this.style.marginRight= 0;
						this.style.marginBottom= 0;
					
						jarvis.extend(wrapDiv,jarvis);

						this.parentNode.appendChild(wrapDiv);
						wrapDiv.appendChild(this);				
					} else {
						var wrapDiv = this;
					}

					if(aAxis != "X"){
						aX = document.createElement("DIV");
//						aX.style.backgroundColor = "red";
						aX.style.position = "absolute";
						aX.style.height = "7px";
						aX.style.width = "100%";
						aX.style.bottom = "-2px";
						aX.style.left = 0;
						aX.style.zIndex = 9997;
						aX.style.cursor = "s-resize";
						jarvis.extend(aX,jarvis);
						wrapDiv.appendChild(aX);
					}

					if(aAxis != "Y"){
						aY = document.createElement("DIV");
//						aY.style.backgroundColor = "red";
						aY.style.position = "absolute";
						aY.style.width = "7px";
						aY.style.height = "100%";
						aY.style.right = "-2px";
						aY.style.top = 0;
						aY.style.zIndex = 9998;
						aY.style.cursor = "e-resize";
						jarvis.extend(aY,jarvis);
						wrapDiv.appendChild(aY);
					}
					
					if(aAxis == "XY"){
						aXY = document.createElement("DIV");
						aXY.style.backgroundColor = "yellow";
						aXY.style.position = "absolute";
						aXY.style.width = "12px";
						aXY.style.height = "12px";
						aXY.style.right = "-4px";
						aXY.style.bottom = "-4px";
						aXY.style.zIndex = 9999;
						aXY.style.cursor = "se-resize";
						jarvis.extend(aXY,jarvis);
						wrapDiv.appendChild(aXY);
					}
					
					if(aAxis == "XY"){
						aXY.drag({
								snapX: snapX,
								snapY: snapY,
								dragging: function(x,y){
												if(target != wrapDiv) {x = this.gL(); y = this.gT();}
												if( x + 12 > (wrapDiv.gL() + minX) ){
													wrapDiv.style.width = x - ((wrapDiv.gL() - 8) + parseInt(wrapDiv.$$("paddingLeft")) + parseInt(wrapDiv.$$("paddingRight"))) + "px";
												} else {
													wrapDiv.style.width = minX + "px";
												}
	
												if(y + 12 > (wrapDiv.gT() + minY)){
													wrapDiv.style.height = y - ((wrapDiv.gT() - 8) + parseInt(wrapDiv.$$("paddingTop")) + parseInt(wrapDiv.$$("paddingBottom")) ) + "px";
												} else {
													wrapDiv.style.height = minY + "px";
												}
												
												this.style.left = wrapDiv.gW()- 8 + "px";
												this.style.top = wrapDiv.gH() + parseInt(wrapDiv.$$("paddingTop")) + parseInt(wrapDiv.$$("paddingBottom")) - 8 + "px";
												
												if(target != wrapDiv){
													target.style.width = wrapDiv.gW() - 4 + "px";
													target.style.height = wrapDiv.gH() - 4 + "px";
												}
	
												aX.style.top = parseInt(this.style.top) + 4 + "px";
												aY.style.left = parseInt(this.style.left) + 4 + "px";
										  }
								});
					}
					
					if(aAxis != "X"){
						aX.drag({
								snapY: snapY,
								axis: "Y",
								dragging: function(x,y){
												if(target != wrapDiv) y = this.gT();
												if(y + 12 > (wrapDiv.gT() + minY)){
													wrapDiv.style.height = y - ((wrapDiv.gT() - 4) + parseInt(wrapDiv.$$("paddingTop")) + parseInt(wrapDiv.$$("paddingBottom"))) + "px";
												} else {
													wrapDiv.style.height = minY + "px";
												}
	
												if(target != wrapDiv) target.style.height = wrapDiv.gH() - 4 + "px";
												this.style.top = wrapDiv.gH() + parseInt(wrapDiv.$$("paddingTop")) + parseInt(wrapDiv.$$("paddingBottom")) + "px";
												if(aAxis == "XY") aXY.style.top = parseInt(this.style.top) - 3 + "px";
										  }
								});
					}

					if(aAxis != "Y"){
						aY.drag({
								snapX: snapX,
								axis: "X",
								dragging: function(x,y){
												if(target != wrapDiv) x = this.gL();
												if( x + 12 > (wrapDiv.gL() + minX) ){
													wrapDiv.style.width = x - ((wrapDiv.gL() - 4) + parseInt(wrapDiv.$$("paddingLeft")) + parseInt(wrapDiv.$$("paddingRight"))) + "px";
												} else {
													wrapDiv.style.width = minX + "px";
													this.style.left = wrapDiv.gL() + wrapDiv.gW() - 4 + "px";
												}
	
												if(target != wrapDiv) target.style.width = wrapDiv.gW() - 4 + "px";
												this.style.left = parseInt(wrapDiv.style.width) - 4 + "px";
												if(aAxis == "XY") aXY.style.left = parseInt(this.style.left) - 3 + "px";
										  }
								});
					}
					return this;
				*/
					if(!opts) opts = {};
					var el = this;
					aAxis = opts.axis || "XY";
					snapY = opts.snapY || 0;
					snapX = opts.snapX || 0;
					minX = minY = 0;
					if(opts.min){
						if(typeof(opts.min) === "string" && opts.min.toLowerCase().indexOf('x') > -1){
							bMin = opts.min.split("x");
							minX = parseInt(bMin[0]);
							minY = parseInt(bMin[1]);
						} else {
							minX = aAxis == "X" ? minX = opts.min : 0;
							minY = aAxis == "Y" ? minY = opts.min : 0;
						}
					}
					bMax = opts.max || 0;
					dBody = document.getElementsByTagName('body')[0];
					var bDiv = document.createElement("DIV");
					el.style.overflow = el.$$("overflow") || "hidden";
					
					if(aAxis == "Y"){
						bDiv.style.height = "10px";
						bDiv.style.position = "absolute";
						bDiv.style.top = ( this.gT() + this.gH() - 9 )+"px";
						bDiv.style.left = parseInt(this.gL()) +"px";
						bDiv.style.width = this.gW() + "px";
						bDiv.style.zIndex = "9999";
						bDiv.style.cursor = "n-resize";
						bDiv.innerHTML = "&nbsp";
						jarvis.extend(bDiv,jarvis);
						el.style.overflow = "hidden";
						tmpY = 0;
						bDiv.drag({
									axis: "Y",
									snapY: snapY,
									snapX: snapX,
									dragging: function(x,y){
													if(parseInt(this.style.top) > (el.gT() + minY)){
														el.style.height = ( parseInt(this.style.top) + 6  - el.gT()) + "px";
													} else {
														el.style.height = minY + "px";
														this.style.top = el.gT() + parseInt(el.style.height) + "px";
													}
											  }
									});
						dBody.appendChild(bDiv);
					} else
					if(aAxis == "X"){
						bDiv.style.position = "absolute";
						bDiv.style.top = this.gT() + 1 +"px";
						bDiv.style.left = this.gL() + this.gW() - 10 +"px";
						bDiv.style.height = this.gH() + "px";
						bDiv.style.width = "10px";
						bDiv.style.zIndex = "9996";
						bDiv.style.cursor = "w-resize";
						bDiv.innerHTML = "&nbsp";
						jarvis.extend(bDiv,jarvis);
						bDiv.drag({
									axis: "X",
									snapY: snapY,
									snapX: snapX,
									dragging: function(x,y){
													if(parseInt(this.style.left) > (el.gL() + minX)){
														el.style.width = ( this.gL() - el.gL() ) + "px";
													} else {
														el.style.width = minX + "px";
														this.style.left = el.gL() + el.gW() + "px";
													}
											  }
									});
						dBody.appendChild(bDiv);
					}
					else {
						bDiv.style.position = "absolute";
						bDiv.style.height = "24px";
						bDiv.style.width = "24px";
						bDiv.style.backgroundColor = "red";
						bDiv.style.top = this.gT() + parseInt(this.gH()) - 20 +"px";
						bDiv.style.left = this.gL() + parseInt(this.gW()) - 20 +"px";
						bDiv.style.zIndex = "9996";
						bDiv.innerHTML = "&nbsp;";
						bDiv.style.cursor = "nw-resize";
						jarvis.extend(bDiv,jarvis);
						bDiv.drag({
									snapY: snapY,
									snapX: snapX,
									dragging: function(x,y){
													if( parseInt(this.style.left) + 20 > (el.gL() + minX) ){
														el.style.width = parseInt(this.style.left) - el.gL() + 20 + "px";
													} else {
														el.style.width = minX + "px";
														this.style.left = el.gL() + parseInt(el.gW()) - 20 + "px";
													}

													if(parseInt(this.style.top) + 20 > (el.gT() + minY)){
														el.style.height = parseInt(this.style.top) - el.gT() + 20 + "px";
													} else {
														el.style.height = minY + "px";
														this.style.top = el.gT() + parseInt(el.gH()) - 20 + "px";
													}

											  }
									});
						dBody.appendChild(bDiv);
					
					}
					
					return this;
				},

	accordion: function(opts){
					var target = this;

					function closeAll() {
						target.find("DD").each(function(ele){
										j$(ele).slideUp({duration: 100});
									});
					}

					this.find('dt').each(function(el){
											var dd = j$(el).next();
											var o = el;
											if(dd.tagName == "DD"){
												dd.$$("display","none");
												el.onclick = function(){
																closeAll();
																dd.slideDown({duration: 100});
															}
											}
										});
			   },
	sorttable: function(){
					var tableEl = this;
					this.tbody = tableEl.getElementsByTagName('tbody');
					this.thead = tableEl.getElementsByTagName('thead');
					this.tfoot = tableEl.getElementsByTagName('tfoot');
				 
					this.getInnerText = function (el) {
						if (typeof(el.textContent) != 'undefined') return el.textContent;
						if (typeof(el.innerText) != 'undefined') return el.innerText;
						if (typeof(el.innerHTML) == 'string') return el.innerHTML.replace(/<[^<>]+>/g,'');
					}
				 
					this.getParent = function (el, pTagName) {
						if (el == null) return null;
						else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
							return el;
						else
							return this.getParent(el.parentNode, pTagName);
					}
				 
					this.sort = function (cell) {
				 
						var column = cell.cellIndex;
						var itm = this.getInnerText(this.tbody[0].rows[1].cells[column]);
						var sortfn = this.sortCaseInsensitive;
				 
						if (itm.match(/\d\d[-]+\d\d[-]+\d\d\d\d/)) sortfn = this.sortDate; // date format mm-dd-yyyy
						if (itm.replace(/^\s+|\s+$/g,"").match(/^[\d\.]+$/)) sortfn = this.sortNumeric;
				 
						this.sortColumnIndex = column;
				 
						var newRows = new Array();
						for (j = 0; j < this.tbody[0].rows.length; j++) {
							newRows[j] = this.tbody[0].rows[j];
						}
				 
						newRows.sort(sortfn);
				 
						if (cell.getAttribute("sortdir") == 'down') {
							newRows.reverse();
							cell.setAttribute('sortdir','up');
						} else {
							cell.setAttribute('sortdir','down');
						}
				 
						for (i=0;i<newRows.length;i++) {
							this.tbody[0].appendChild(newRows[i]);
						}
				 
					}
				 
					this.sortCaseInsensitive = function(a,b) {
						aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]).toLowerCase();
						bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]).toLowerCase();
						if (aa==bb) return 0;
						if (aa<bb) return -1;
						return 1;
					}
				 
					this.sortDate = function(a,b) {
						aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]);
						bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]);
						date1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
						date2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
						if (date1==date2) return 0;
						if (date1<date2) return -1;
						return 1;
					}
				 
					this.sortNumeric = function(a,b) {
						aa = parseFloat(thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]));
						if (isNaN(aa)) aa = 0;
						bb = parseFloat(thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]));
						if (isNaN(bb)) bb = 0;
						return aa-bb;
					}
				 
					// define variables
					var thisObject = this;
					var sortSection = this.thead;
				 
					// constructor actions
					if (!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length > 0)) return;
				 
					if (sortSection && sortSection[0].rows && sortSection[0].rows.length > 0) {
						var sortRow = sortSection[0].rows[0];
					} else {
						return;
					}
				 
					for (var i=0; i<sortRow.cells.length; i++) {
						sortRow.cells[i].sTable = this;
						sortRow.cells[i].onclick = function () {
							this.sTable.sort(this);
							return false;
						}
					}
				},

	chain: function () {
				var target=this;
				var que = []
				function callNext() {
					que.length && que.shift()();
				}
				return {
					scrollTo : function(opts){
								if(!opts) opts={}
									que.push(function() {
										target.scrollTo(opts, callNext);
									});
								return this;
								},
					animate: function(opts) {
								if(!opts) opts={}
									que.push(function() {
										target.animate(opts, callNext);
									});
								return this;
							 },
					slideUp: function(opts) {
								if(!opts) opts={}
									que.push(function() {
										target.slideUp(opts, callNext);
									});
								return this;
							 },
					slideDown: function(opts) {
									que.push(function() {
										target.slideDown(opts, callNext);
									});
								return this;
							  },
					fadeIn: function(opts) {
								if(!opts) opts={}
									que.push(function() {
										target.fadeIn(opts, callNext);
									});
								return this;
							 },
					fadeOut: function(opts) {
								if(!opts) opts={}
									que.push(function() {
										target.fadeOut(opts, callNext);
									});
								return this;
							 },
					drag: function(opts) {
								if(!opts) opts={}
									que.push(function() {
										target.drag(opts, callNext);
									});
								return this;
							 },
					pause: function(duration) {
									que.push(function() {
										target.pause(duration, callNext);
									});
								return this;
							 },
					end: callNext
				};
			}
}

jarvis.extend(jFx);